package org.smile.tomcat.session;

import java.io.IOException;

import org.apache.catalina.Container;
import org.apache.catalina.Context;
import org.apache.catalina.Lifecycle;
import org.apache.catalina.session.ManagerBase;

public abstract class StoreManager extends ManagerBase implements Lifecycle{

	@Override
	public void load() throws ClassNotFoundException, IOException {
		
	}

	@Override
	public void unload() throws IOException {
		
	}
	
	public abstract void afterRequest();
	
	/**
	 * 获取session最大活动时长
	 * @return
	 */
	public int getMaxSessionTimeout(){
		Context context = context();
		if(context!=null) {
			return context.getSessionTimeout() * 60;
		}
		return -1;
	}

	public Context context(){
		Container container = getContainer();
		if ((container instanceof Context)){
			return (Context) container;
		}
		return null;
	}
}
